// 通用类型定义
export interface ApiResponse<T> {
  code: number
  message: string
  data: T
}

export interface PaginationParams {
  page: number
  pageSize: number
  total?: number
}

export interface TableColumn {
  title: string
  dataIndex: string
  key: string
  width?: number
  render?: (value: any, record: any) => React.ReactNode
}

// 用户相关类型
export interface User {
  id: string
  username: string
  email: string
  role: 'admin' | 'manager' | 'operator'
  avatar?: string
  phone?: string
  department?: string
  status: 'active' | 'inactive'
  createdAt: string
  lastLogin?: string
}

// 设备相关类型
export interface Device {
  id: string
  name: string
  type: 'hvac' | 'lighting' | 'elevator' | 'security' | 'parking'
  location: string
  status: 'online' | 'offline' | 'warning' | 'maintenance'
  lastUpdate: string
  specifications?: Record<string, any>
  maintenanceSchedule?: string
  energyConsumption?: number
}

// 人员相关类型
export interface Personnel {
  id: string;
  name: string;
  department: string;
  position: string;
  phone: string;
  email: string;
  status: 'active' | 'inactive';
  entryTime?: string;
  avatar?: string;
}

// 能耗数据类型
export interface EnergyData {
  totalConsumption: number
  cost: number
  efficiency: number
  carbonEmission: number
  dailyData: Array<{
    date: string
    consumption: number
    cost: number
    peak: number
  }>
  deviceBreakdown: Array<{
    deviceType: string
    consumption: number
    percentage: number
    trend: 'up' | 'down' | 'stable'
  }>
  realTimeMetrics: {
    currentPower: number
    voltage: number
    current: number
    powerFactor: number
    frequency: number
  }
}

// 安全相关类型
export interface SecurityEvent {
  id: string
  type: 'intrusion' | 'fire' | 'equipment_failure' | 'access_violation'
  severity: 'low' | 'medium' | 'high' | 'critical'
  location: string
  description: string
  timestamp: string
  status: 'pending' | 'investigating' | 'resolved' | 'false_alarm'
  assignedTo?: string
  resolvedAt?: string
  images?: string[]
  videoUrl?: string
}

// 停车相关类型
export interface ParkingSpace {
  id: string
  number: string
  zone: string
  type: 'standard' | 'compact' | 'disabled' | 'electric'
  status: 'available' | 'occupied' | 'reserved' | 'maintenance'
  vehicleInfo?: {
    plateNumber: string
    entryTime: string
    expectedExit?: string
  }
  sensors: {
    occupancy: boolean
    lastUpdate: string
  }
}

export interface Vehicle {
  id: string;
  plateNumber: string;
  owner: string;
  type: 'car' | 'truck' | 'motorcycle';
  entryTime?: string;
  exitTime?: string;
  parkingSpace?: string;
}

// 访客相关类型
export interface Visitor {
  id: string
  name: string
  phone: string
  company?: string
  purpose: string
  hostEmployee: string
  entryTime: string
  expectedExitTime: string
  actualExitTime?: string
  status: 'pending' | 'approved' | 'rejected' | 'checked_in' | 'checked_out'
  idCard?: string
  photo?: string
  accessAreas: string[]
}

// 仪表板统计类型
export interface DashboardStats {
  totalDevices: number;
  onlineDevices: number;
  totalPersonnel: number;
  activePersonnel: number;
  totalParkingSpaces: number;
  occupiedSpaces: number;
  securityEvents: number;
  energyConsumption: number;
}

// API 响应类型
export interface ApiResponse<T> {
  success: boolean;
  data: T;
  message?: string;
  code?: number;
}

// 分页类型
export interface Pagination {
  current: number;
  pageSize: number;
  total: number;
}

// 表格列配置类型
export interface TableColumn {
  title: string;
  dataIndex: string;
  key: string;
  width?: number;
  sorter?: boolean;
  filters?: Array<{ text: string; value: any }>;
  render?: (value: any, record: any) => React.ReactNode;
}

// 巡检相关类型
export interface InspectionPlan {
  id: string
  name: string
  type: 'safety' | 'equipment' | 'environment'
  frequency: 'daily' | 'weekly' | 'monthly'
  nextDate: string
  status: 'active' | 'inactive'
  assignee: string
  checkpoints: number
  completedCount: number
}

export interface InspectionRecord {
  id: string
  planId: string
  planName: string
  inspector: string
  startTime: string
  endTime?: string
  status: 'pending' | 'in_progress' | 'completed'
  score?: number
  issues: number
  photos: string[]
  checkpoints: CheckPoint[]
}

export interface CheckPoint {
  id: string
  name: string
  status: 'normal' | 'warning' | 'error'
  notes?: string
  photos?: string[]
  timestamp: string
}

// 客服相关类型
export interface Conversation {
  id: string
  user: string
  lastMessage: string
  time: string
  status: 'active' | 'waiting' | 'closed'
  type: 'chat' | 'phone' | 'email'
  priority: 'low' | 'normal' | 'high'
}

export interface Message {
  id: string
  sender: 'user' | 'agent' | 'bot'
  content: string
  time: string
  type: 'text' | 'image' | 'file'
}

export interface KnowledgeBase {
  id: string
  question: string
  answer: string
  category: string
  hits: number
  tags?: string[]
}

// 排班相关类型
export interface Schedule {
  id: string
  date: string
  shift: 'morning' | 'afternoon' | 'night'
  employee: string
  department: string
  position: string
  status: 'pending' | 'confirmed' | 'cancelled'
}

export interface Employee {
  id: string
  name: string
  department: string
  position: string
  skills: string[]
  availability: string[]
}

// 预警相关类型
export interface Alert {
  id: string
  title: string
  type: string
  level: 'low' | 'medium' | 'high' | 'critical'
  status: 'active' | 'acknowledged' | 'resolved'
  value: number
  threshold: number
  location: string
  time: string
  description: string
}

export interface AlertRule {
  id: string
  name: string
  type: string
  condition: 'greater_than' | 'less_than' | 'equals'
  threshold: number
  enabled: boolean
  actions: string[]
}

// 智能分析相关类型
export interface AnalyticsData {
  energyTrend: number[]
  occupancyRate: number
  deviceHealth: number
  securityScore: number
  predictions: Prediction[]
}

export interface Prediction {
  type: string
  value: number
  confidence: number
  timeframe: string
}
